home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pdcurs21.zip / PORTABLE.ZIP / SUBWIN.C < prev    next >
Text File  |  1992-11-21  |  4KB  |  105 lines

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #define        CURSES_LIBRARY  1
  4. #include <curses.h>
  5. #undef subwin
  6.  
  7. #ifndef        NDEBUG
  8. char *rcsid_subwin = "$Header: c:/curses/portable/RCS/subwin.c%v 2.0 1992/11/15 03:29:24 MH Rel $";
  9. #endif
  10.  
  11.  
  12.  
  13.  
  14. /*man-start*********************************************************************
  15.  
  16.   subwin()     - create subwindow
  17.  
  18.   X/Open Description:
  19.        This routine creates a new sub-window within a window.  The
  20.        dimensions of the sub-window are nlines lines and ncols
  21.        columns.  The sub-window is at position (begin_y, begin_x) on
  22.        the screen.  This position is relative to the screen, and not
  23.        to the window orig.
  24.  
  25.        The sub-window is made in the middle of the window orig, so
  26.        that changes made to either window will affect both.  When
  27.        using this routine, it will often be necessary to call
  28.        touchwin before calling wrefresh.
  29.  
  30.   PDCurses Description:
  31.        No additional PDCurses functionality.
  32.  
  33.   X/Open Return Value:
  34.        On success the subwin function returns a pointer to the new
  35.        WINDOW structure created.  On failure the function returns a
  36.        null pointer.
  37.  
  38.   PDCurses Errors:
  39.        It is an error to pass sub-window coordinates that are out of
  40.        range or a NULL WINDOW pointer.  subwin() may also return an
  41.        error if it fails to allocate enough memory for the window
  42.        structure.
  43.  
  44.   Portability:
  45.        PDCurses        WINDOW* subwin( WINDOW* orig, int nlines,
  46.                                int ncols, int begin_y, int begin_x );
  47.        X/Open Dec '88  WINDOW* subwin( WINDOW* orig, int nlines,
  48.                                int ncols, int begin_y, int begin_x );
  49.        BSD Curses      WINDOW* subwin( WINDOW* orig, int nlines,
  50.                                int ncols, int begin_y, int begin_x );
  51.        SYS V Curses    WINDOW* subwin( WINDOW* orig, int nlines,
  52.                                int ncols, int begin_y, int begin_x );
  53.  
  54. **man-end**********************************************************************/
  55.  
  56. WINDOW*        subwin(WINDOW* orig,int nlines,int ncols,int begin_y,int begin_x)
  57. {
  58. extern void*   (*mallc)( size_t );
  59. extern void*   (*callc)( size_t, size_t );
  60. extern void    (*fre)( void* );
  61.  
  62.        WINDOW* win;
  63.        int     i;
  64.        int     j = begin_y - orig->_begy;
  65.        int     k = begin_x - orig->_begx;
  66.  
  67.        if (!orig)
  68.                return( (WINDOW *)NULL );
  69.  
  70.        /*
  71.         * make sure window fits inside the original one
  72.         */
  73.        if ((begin_y < orig->_begy) ||
  74.            (begin_x < orig->_begx) ||
  75.            (begin_y + nlines) > (orig->_begy + orig->_maxy) ||
  76.            (begin_x + ncols)  > (orig->_begx + orig->_maxx))
  77.        {
  78.                return( (WINDOW *)NULL );
  79.        }
  80.        if (!nlines)    nlines = orig->_maxy - 1 - j;
  81.        if (!ncols)     ncols  = orig->_maxx - 1 - k;
  82.        if ((win = PDC_makenew(nlines, ncols, begin_y, begin_x)) == (WINDOW *) NULL)
  83.        {
  84.                return( (WINDOW *)NULL );
  85.        }
  86.  
  87.        /*
  88.         * initialize window variables
  89.         */
  90.        win->_attrs     = orig->_attrs;
  91.        win->_leave     = orig->_leave;
  92.        win->_scroll    = orig->_scroll;
  93.        win->_nodelay   = orig->_nodelay;
  94.        win->_use_keypad        = orig->_use_keypad;
  95.        win->_parent    = orig;
  96.  
  97.        for (i = 0; i < nlines; i++)
  98.        {
  99.                win->_y[i] = (orig->_y[j++]) + k;
  100.        }
  101.  
  102.        win->_flags |= _SUBWIN;
  103.        return (win);
  104. }
  105.